﻿import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../../js/UI.js" as Style
import "../common"
import "../../js/util.js" as Util
Rectangle {
    id: rect
    property alias m_headSource: m_head.m_source
    property alias m_name: m_NameText_id.text
    property alias m_name_id: m_NameText_id
    property alias m_sipSource: m_StatuImg_id.source
    property alias a_phoneText:phonetext
    property var onlinestatus:""
    property bool serchmode: false;
    property bool showStatus: false
    signal clickSignal()
    signal pressSignal()
    color: "transparent"
    width: m_root_id.width
    height: m_lineValue*1.1
    signal enterCignal()
    signal  exitClick()

    HeadImage {
        id: m_head
        width: parent.height*0.8
        height: parent.height*0.8
        anchors.left: parent.left
        anchors.leftMargin: m_lineValue*0.4
        anchors.verticalCenter: parent.verticalCenter
        nameText: m_NameText_id.text.substring(0,1)
        colorText:m_NameText_id.text.length>1?m_NameText_id.text.substring(1,2):""
    }
    Image{
        visible: showStatus
        sourceSize.width:0.38*m_lineValue
        sourceSize.height:0.38*m_lineValue
        anchors.left: m_head.left
        anchors.leftMargin: m_head.width-0.25*m_lineValue
        anchors.bottom: m_head.bottom
        //        anchors.bottomMargin: m_head.height-0.34*m_lineValue
        source: {
            if(onlinestatus == 2 || onlinestatus == 3 || onlinestatus == 4)
                return "qrc:/pc/images/PC/t_online.svg"
            else if(onlinestatus == 1)
                return "qrc:/pc/images/PC/t_offline.svg"
            else if(onlinestatus == 0)
                return "qrc:/pc/images/PC/t_unknown.svg"
            else
                return  "qrc:/pc/images/PC/t_unknown.svg"
        }
    }

    Item {
        width: m_root_id.width - m_lineValue*2
        anchors.left: m_head.right
        anchors.leftMargin: m_lineValue*0.2
        height: parent.height*0.8
        anchors.verticalCenter: parent.verticalCenter
        AText {
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.topMargin: phonetext.text===""?(parent.height-paintedHeight)/2:(parent.height/2-paintedHeight)/2
            id: m_NameText_id
            width: parent.width
            font.pointSize: 16
            elide: Text.ElideRight
            wrapMode: Text.NoWrap
        }

        AText{
            id: phonetext
            anchors.bottom: parent.bottom
            anchors.bottomMargin: (parent.height/2-paintedHeight)/2
            font.pointSize: 14
            elide: Text.ElideRight
            wrapMode: Text.NoWrap
            color: "#808080"
            width: parent.width
            text:{
                if(!serchmode) return "";
                if(model.phone1 != undefined && model.phone1.search(m_searchText_id.m_text)!==-1)
                    return model.phone1.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else if(model.sipuri != undefined && model.sipuri.search(m_searchText_id.m_text)!==-1)
                    return model.sipuri.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else if(model.phone2 != undefined && model.phone2.search(m_searchText_id.m_text)!==-1)
                    return model.phone2.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else if(model.phone3 != undefined && model.phone3.search(m_searchText_id.m_text)!==-1)
                    return model.phone3.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else if(model.phone4 != undefined && model.phone4.search(m_searchText_id.m_text)!==-1)
                    return model.phone4.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else if(model.phone5 != undefined && model.phone5.search(m_searchText_id.m_text)!==-1)
                    return model.phone5.replace(m_searchText_id.m_text,"<font size='4' color='#1991eb'>%1</font>").arg(m_searchText_id.m_text);
                else return ""
            }
        }
    }
    Image{
        id: m_StatuImg_id
        width: m_lineValue*0.4
        anchors {
            right: parent.right
            rightMargin: m_lineValue*0.6
            verticalCenter: parent.verticalCenter
        }
        height: width
        fillMode: Image.PreserveAspectFit
    }
    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: {
            clickSignal()
        }
        onPressed:{
            pressSignal()
        }
        onEntered: enterCignal()
        onExited: exitClick()
        hoverEnabled:true
    }
    states: State {
        name: "pressed"; when: mouseArea.pressed
        PropertyChanges { target: rect ; color: Style.transparent_color;}
    }
    transitions: Transition {
    }
}

